<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将数组开头的单元移出数组</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.array-shift" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_shift</h1>
    <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">array_shift</span> &mdash; <span class="dc-title">
     将数组开头的单元移出数组
    </span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.array-shift-description">
  <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>array_shift</strong></span>
       ( <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$array</code></span>
      ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_shift()</strong></span> 将
     <code class="parameter">array</code> 的第一个单元移出并作为结果返回，将
     <code class="parameter">array</code> 的长度减一并将所有其它单元向前移动一位。所有的数字键名将改为从零开始计数，文字键名将不变。
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">使用此函数后会重置（<span class="function"><a href="reset.html" class="function">reset()</a></span>）<span class="type"><a href="language.types.array.html" class="type array">array</a></span>
指针。</span></p></blockquote>
   </div>

 <div class="refsect1 parameters" id="refsect1-function.array-shift-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">array</code></dt>

     <dd>

      <p class="para">
       输入的数组。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.array-shift-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回移出的值，如果 <code class="parameter">array</code> 为 空或不是一个数组则返回 <strong><code>NULL</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.array-shift-examples">
  <h3 class="title">范例</h3>
  <p class="para">
    <div class="example" id="example-6065">
     <p><strong>Example #1 <span class="function"><strong>array_shift()</strong></span> 例子</strong></p>
     <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$stack&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"orange"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"banana"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"apple"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"raspberry"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fruit&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_shift</span><span style="color: #007700">(</span><span style="color: #0000BB">$stack</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$stack</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
     </div>

     <div class="example-contents"><p>以上例程会输出：</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; banana
    [1] =&gt; apple
    [2] =&gt; raspberry
)
</pre></div>
     </div>
     <div class="example-contents"><p>
      并且 <em>orange</em> 被赋给了 <var class="varname"><var class="varname">$fruit</var></var>。
     </p></div>
    </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.array-shift-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="array_unshift.html" class="function" rel="rdfs-seeAlso">array_unshift()</a> - 在数组开头插入一个或多个单元</span></li>
    <li class="member"><span class="function"><a href="array_push.html" class="function" rel="rdfs-seeAlso">array_push()</a> - 将一个或多个单元压入数组的末尾（入栈）</span></li>
    <li class="member"><span class="function"><a href="array_pop.html" class="function" rel="rdfs-seeAlso">array_pop()</a> - 弹出数组最后一个单元（出栈）</span></li>
   </ul>
  </p>
 </div>

  </div></div></div></body></html>